package com.bocloud.cmp.driver.convertor.os;

import java.util.List;

import org.openstack4j.model.compute.ext.Hypervisor;

import com.bocloud.cmp.driver.convertor.BeanConvert;
import com.bocloud.cmp.model.HostModel;
import com.google.common.collect.Lists;

public class ConvertHyperV implements BeanConvert<HostModel, Hypervisor> {

	@Override
	public List<HostModel> convertList(List<? extends Hypervisor> hyperVs) {
		List<HostModel> hostModels = Lists.newArrayList();
		for (Hypervisor hyperv : hyperVs) {
			hostModels.add(convertModel(hyperv));
		}
		return hostModels;
	}

	@Override
	public HostModel convertModel(Hypervisor hyperv) {
		HostModel hostModel = new HostModel();
		hostModel.setUuid(hyperv.getId());// uuid
		hostModel.setCatalog("OPENSTACK");
		hostModel.setName(hyperv.getHypervisorHostname());
		hostModel.setHostIp(hyperv.getHostIP());
		hostModel.setCpuTotal((long) hyperv.getVirtualCPU());
		hostModel.setMemTotal((long) hyperv.getLocalMemory());
		hostModel.setDiskTotal((long) hyperv.getLocalDisk());
		hostModel.setCpuUsed((long) hyperv.getVirtualUsedCPU());
		hostModel.setMemUsed((long) hyperv.getLocalMemoryUsed());
		hostModel.setDiskUsed((long) hyperv.getLocalDiskUsed());
		hostModel.setCpuModel(hyperv.getCPUInfo().getModel());
		hostModel.setVendor(hyperv.getCPUInfo().getVendor());
		hostModel.setVmNum(hyperv.getRunningVM());
		hostModel.setPowerState(hyperv.getState());
		hostModel.setStatus(hyperv.getStatus());
		hostModel.setCpuNum(hyperv.getCPUInfo().getTopology().getSockets());
		hostModel.setCpuCore(hyperv.getCPUInfo().getTopology().getCores());

		return hostModel;
	}

}